package com.gree.flowable.app.tools.utils;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

import java.lang.reflect.Type;
import java.sql.Timestamp;

public class JsonUtils {
    public JsonUtils() {
    }

    public static Object jsonToObj(String json, Class clazz) {
        return getGson().fromJson(json, clazz);
    }

    public static Gson getGson() {
        GsonBuilder gsonBuilder = new GsonBuilder();
        gsonBuilder.setDateFormat("yyyy-MM-dd HH:mm:ss");
        gsonBuilder.registerTypeAdapter(Timestamp.class, new TimestampTypeAdapter());
        Gson GSON = gsonBuilder.create();
        return GSON;
    }

    public static String toJson(Object obj) {
        return getGson().toJson(obj);
    }

    public static String toJson(Object obj, Type typeToken) {
        return getGson().toJson(obj, typeToken);
    }
}
